package file;

import java.io.File;
import java.io.IOException;

import utils.FileUtils;

public class CreateFile {
	public static void main(String[] args) throws IOException {
		String path = "D:/kvin/naruto/peien";
		createFile("D:/kvin/img.jpg");
		createFile(path);
		createFile(path + "/face");
		for (int i = 0; i < 10; i++) {
			createFile(path + i);
			for (int j = 0; j < 10; j++) {
				createFile(path + i + "/" + (int) (Math.random() * 10000)
						+ ".jpg");
			}
		}

	}

	// defined delete
	private static boolean myDelete(File file1) {
		File file = file1;
		String temp = "";
		if (file.exists()) {
			while (!file.getName().equals("")) {

				temp = file.getParent();
				file.delete();
				file = new File(temp);
			}
			return true;
		}

		return false;
	}

	static void p(Object o) {
		System.out.println(o);
	}

	// create file
	static void createFile(String path) {
		int i = path.lastIndexOf(".");
		if (i == -1) {
			File f = new File(path);
			if (!f.exists()) {
				if (f.mkdirs())
					p("create successfully");
				;
			}
		} else {
			String prefix = path.substring(0, path.lastIndexOf("/"));
			File f1 = new File(prefix);
			if (!f1.exists()) {
				f1.mkdirs();
			}
			File f2 = new File(path);
			if (!f2.exists()) {
				try {
					if (f2.createNewFile())
						p("cteate successfully");
				} catch (IOException e) {
					// TODO Auto-generated catch block
					e.printStackTrace();
				}
			}

		}
	}
}
